<?php

namespace App\Http\Requests\customer;

use App\Http\ValidateResult;
use Illuminate\Support\Facades\Validator;

trait CallBackRequest
{
    public static function status_received(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'bigBagID' => 'required',
            'status' => 'required',
            'status_date' => 'required',
            'event_location_code' => 'required',
            'event_location_name' => 'required'
        ], [
            'bigBagID.required' => '大包号不能为空',
            'status.required' => '状态不能为空',
            'status_date.required' => '作业时间不能为空',
            'event_location_code.required' => '时间发生地编码不能为空',
            'event_location_name.required' => '时间发生地不能为空',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function status_prebooking(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'bigBagID' => 'required',
            'status' => 'required',
            'status_date' => 'required',
            'event_location_code' => 'required',
            'event_location_name' => 'required',
            'airline_code' => 'required',
            'airline_name' => 'required',
            'flight_number' => 'required',
            'flight_etd' => 'required',
            'flight_eta' => 'required',
        ], [
            'bigBagID.required' => '大包号不能为空',
            'status.required' => '状态不能为空',
            'status_date.required' => '作业时间不能为空',
            'event_location_code.required' => '时间发生地编码不能为空',
            'event_location_name.required' => '时间发生地不能为空',
            'airline_code.required' => '航空公司编码不能为空',
            'airline_name.required' => '航空公司名称不能为空',
            'flight_number.required' => '航班号不能为空',
            'flight_etd.required' => '航班预计离港时间不能为空',
            'flight_eta.required' => '航班预计到港时间不能为空',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function status_preadvice(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'bigBagID' => 'required',
            'status' => 'required',
            'status_date' => 'required',
            'event_location_code' => 'required',
            'event_location_name' => 'required',
            'origin_country_code' => 'required',
            'origin_country_name' => 'required',
            'origin_airport_code' => 'required',
            'destination_country_code' => 'required',
            'destination_country_name' => 'required',
            'destination_airport_code' => 'required',
            'airline_code' => 'required',
            'airline_name' => 'required',
            'flight_number' => 'required',
            'flight_etd' => 'required',
            'flight_eta' => 'required',
            'mawb_number' => 'required'
        ], [
            'bigBagID.required' => '大包号不能为空',
            'status.required' => '状态不能为空',
            'status_date.required' => '作业时间不能为空',
            'event_location_code.required' => '时间发生地编码不能为空',
            'event_location_name.required' => '时间发生地不能为空',
            'origin_country_code.required' => '始发国编码不能为空',
            'origin_country_name.required' => '始发国名称不能为空',
            'origin_airport_code.required' => '始发机场不能为空',
            'destination_country_code.required' => '目的地国家编码不能为空',
            'destination_country_name.required' => '目的地国家名称不能为空',
            'destination_airport_code.required' => '目的地机场不能为空',
            'airline_code.required' => '航空公司编码不能为空',
            'airline_name.required' => '航空公司名称不能为空',
            'flight_number.required' => '航班号不能为空',
            'flight_etd.required' => '航班预计离港时间不能为空',
            'flight_eta.required' => '航班预计到港时间不能为空',
            'mawb_number.required' => 'mawb_number不能为空'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function status_uplifted(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'bigBagID' => 'required',
            'status' => 'required',
            'status_date' => 'required',
            'event_location_code' => 'required',
            'event_location_name' => 'required',
            'origin_country_code' => 'required',
            'origin_country_name' => 'required',
            'origin_airport_code' => 'required',
            'destination_country_code' => 'required',
            'destination_country_name' => 'required',
            'destination_airport_code' => 'required',
            'airline_code' => 'required',
            'airline_name' => 'required',
            'flight_number' => 'required',
            'mawb_number' => 'required',
        ], [
            'bigBagID.required' => '大包号不能为空',
            'status.required' => '状态不能为空',
            'status_date.required' => '作业时间不能为空',
            'event_location_code.required' => '时间发生地编码不能为空',
            'event_location_name.required' => '时间发生地不能为空',
            'origin_country_code.required' => '始发国编码不能为空',
            'origin_country_name.required' => '始发国名称不能为空',
            'origin_airport_code.required' => '始发机场不能为空',
            'destination_country_code.required' => '目的地国家编码不能为空',
            'destination_country_name.required' => '目的地国家名称不能为空',
            'destination_airport_code.required' => '目的地机场不能为空',
            'airline_code.required' => '航空公司编码不能为空',
            'airline_name.required' => '航空公司名称不能为空',
            'flight_number.required' => '航班号不能为空',
            'mawb_number.required' => 'mawb_number不能为空',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }


    public static function status_arrived(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'bigBagID' => 'required',
            'status' => 'required',
            'status_date' => 'required',
            'event_location_code' => 'required',
            'event_location_name' => 'required',
            'origin_country_code' => 'required',
            'origin_country_name' => 'required',
            'origin_airport_code' => 'required',
            'destination_country_code' => 'required',
            'destination_country_name' => 'required',
            'destination_airport_code' => 'required',
            'airline_code' => 'required',
            'airline_name' => 'required',
            'flight_number' => 'required',
            'booking_type' => 'required',
            'transport_type' => 'required',
        ], [
            'bigBagID.required' => '大包号不能为空',
            'status.required' => '状态不能为空',
            'status_date.required' => '作业时间不能为空',
            'event_location_code.required' => '时间发生地编码不能为空',
            'event_location_name.required' => '时间发生地不能为空',
            'origin_country_code.required' => '始发国编码不能为空',
            'origin_country_name.required' => '始发国名称不能为空',
            'origin_airport_code.required' => '始发机场不能为空',
            'destination_country_code.required' => '目的地国家编码不能为空',
            'destination_country_name.required' => '目的地国家名称不能为空',
            'destination_airport_code.required' => '目的地机场不能为空',
            'airline_code.required' => '航空公司编码不能为空',
            'airline_name.required' => '航空公司名称不能为空',
            'flight_number.required' => '航班号不能为空',
            'booking_type.required' => 'booking_type不能为空',
            'transport_type.required' => 'transport_type不能为空',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function airline_callback(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'mawbNo' => 'required',
            'transportNo' => 'required',
            'ETD' => 'required',
            'fromPortCode' => 'required',
            'toPortCode' => 'required',
            'opTime' => 'required',
            'timeZone' => 'required',
            'operator' => 'required',
            'opCode' => 'required',
            'bookingType' => 'required',
            'bigBagList' => 'required|array',
        ], [
            'mawbNo.required' => '提单号不能为空',
            'transportNo.required' => '航班号不能为空',
            'ETD.required' => '航班起飞时间不能为空',
            'fromPortCode.required' => '起始港不能为空',
            'toPortCode.required' => '目的港不能为空',
            'opTime.required' => '作业时间不能为空',
            'timeZone.required' => '时区不能为空',
            'operator.required' => '当前操作CP的资源code不能为空',
            'opCode.required' => '作业结果代码不能为空',
            'bookingType.required' => '舱位类型不能为空',
            'bigBagList.required' => '大包列表不能为空',
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function exception_callback(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'logisticsOrderCode' => 'required',
            'trackingNumber' => 'required',
            'bigBagID' => 'required',
            'exceptionStatus' => 'required',
            'returnToSc' => 'required',
            'opTime' => 'required',
            'timeZone' => 'required',
            'operator' => 'required',
        ], [
            'logisticsOrderCode.required' => '物流单号不能为空',
            'trackingNumber.required' => '运单号不能为空',
            'bigBagID.required' => '大包号不能为空',
            'exceptionStatus.required' => '定义的异常不能为空',
            'returnToSc.required' => '退回分拨不能为空',
            'opTime.required' => '作业时间不能为空',
            'timeZone.required' => '时区不能为空',
            'operator.required' => '当前操作CP的资源code不能为空'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function prebooking_callback(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'mawbNo' => 'required',
            'originPort' => 'required',
            'destinationPort' => 'required',
            'PCS' => 'required',
            'pieceList' => 'required',
            'interlineFlightList' => 'required',
            'bookingType' => 'required',
            'opTime' => 'required',
            'timeZone' => 'required',
            'operator' => 'required',
        ], [
            'mawbNo.required' => '提单号不能为空',
            'originPort.required' => '航班起始港不能为空',
            'destinationPort.required' => '航班目的港不能为空',
            'PCS.required' => '提单件数不能为空',
            'pieceList.required' => '大包列表不能为空',
            'interlineFlightList.required' => '多程航班不能为空',
            'bookingType.required' => '订舱类型不能为空',
            'opTime.required' => '作业时间不能为空',
            'timeZone.required' => '时区不能为空',
            'operator.required' => '当前操作CP的资源code不能为空'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

    public static function hoairline_callback_check(array $params): ValidateResult {
        $validator = Validator::make($params, [
            'logisticsOrderCode' => 'required',
            'trackingNumber' => 'required',
            'opTime' => 'required',
            'timeZone' => 'required',
            'operator' => 'required'
        ], [
            'logisticsOrderCode.required' => '物流单号不能为空',
            'trackingNumber.required' => '运单号不能为空',
            'opTime.required' => '作业时间不能为空',
            'timeZone.required' => '时区不能为空',
            'operator.required' => '当前操作CP的资源code不能为空'
        ]);

        if ($validator->fails()) {
            return ValidateResult::error($validator->errors()->first());
        }
        return ValidateResult::correct();
    }

}
